package com.minwei.bigrichman.result;

import lombok.Data;

/**
 * @author: <a href="xjm01611253@alibaba-inc.com">肖建民</a>
 * @date: 2024/8/9
 * @time: 16:28
 * @description:
 */
@Data
public class CommonResult<T> {
    private T data;
    private boolean success;
    private String errorCode;
    private String errorMsg;

    public static <T> CommonResult<T> success(T data) {
        CommonResult<T> commonResult = new CommonResult<>();
        commonResult.setSuccess(true);
        commonResult.setData(data);
        return commonResult;
    }

    public static <T> CommonResult<T> success() {
        CommonResult<T> commonResult = new CommonResult<>();
        commonResult.setSuccess(true);
        return commonResult;
    }

    public static <T> CommonResult<T> fail(String errorCode, String errorMsg) {
        CommonResult<T> commonResult = new CommonResult<>();
        commonResult.setSuccess(false);
        commonResult.setErrorCode(errorCode);
        commonResult.setErrorMsg(errorMsg);
        return commonResult;
    }
}
